//
//  RCMerchantCommentListDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-9-9.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCMerchantCommentListDataModel.h"
#import "FrameworkRelativeDefines.h"
#import "NSArray+EX.h"

@implementation RCMerchantCommentListItem

@synthesize userName = _userName;
@synthesize score = _score;
@synthesize price = _price;
@synthesize content = _content;
@synthesize dateTime = _dateTime;

-(id)init{
    self = [super init];
    if (self) {
        _userName = nil;
        _score = 0;
        _price = nil;
        _content = nil;
        _dateTime = nil;
        _openState = NO;
    }
    return self;
}

-(void)dealloc{
    self.userName = nil;
    self.price = nil;
    self.content = nil;
    self.dateTime = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    
    RCMerchantCommentListItem *retObject = nil;
    retObject = [[RCMerchantCommentListItem alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.userName = [data stringValueForKey:@"username" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.score = [data intValueForKey:@"score" defaultValue:0];
    retObject.price = [data stringValueForKey:@"price" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.content = [data stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.dateTime = [data stringValueForKey:@"datetime" defaultValue:nil operation:NSStringOperationTypeTrim];
    if (nil == retObject.dateTime) {
        retObject.dateTime = [data stringValueForKey:@"date" defaultValue:nil operation:NSStringOperationTypeTrim];
    }
    retObject.openState = NO;
    return [retObject autorelease];

}

@end

@implementation RCMerchantCommentListDataModel

@synthesize commentItemList = _commentItemList;
@synthesize total = _total;

-(id)init{
    self = [super init];
    if (self) {
        _commentItemList = nil;
        _total = 0;
    }
    return self;
}

-(void)dealloc{
    self.commentItemList = nil;
    [super dealloc];
}

+(id)parseDataFromJSON:(NSDictionary *)data{
    if (nil == data) {
        return nil;
    }
    NSDictionary *dict = [data dictionaryValueForKey:@"data" defaultValue:nil];
    if (nil == dict) {
        return nil;
    }
    
    NSArray *itemDictArray = [dict arrayValueForKey:@"items" defaultValue:nil];
    if (nil == itemDictArray) {
        return nil;
    }
    RCMerchantCommentListDataModel *retObject = nil;
    retObject = [[RCMerchantCommentListDataModel alloc]init];
    if (nil == retObject) {
        return nil;
    }
    retObject.total = [dict intValueForKey:@"total" defaultValue:0];
    NSMutableArray *itemTempArray = [[NSMutableArray alloc]initWithCapacity:1];
    for (int i = 0; i < [itemDictArray count]; i++) {
        NSDictionary *itemDict = [itemDictArray safeObjectAtIndex:i];
        if (nil == itemDict) {
            continue;
        }
        
        RCMerchantCommentListItem *item = [RCMerchantCommentListItem parseDataFromJSON:itemDict];
        if (nil == item) {
            continue;
        }
        [itemTempArray addObject:item];
    }
    retObject.commentItemList = [NSArray arrayWithArray:itemTempArray];
    [itemTempArray release];
    return [retObject autorelease];

}

@end
